home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWFiles / FWFileSp.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  14.5 KB  |  501 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFileSp.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFILESP_H
  13. #include "FWFileSp.h"
  14. #endif
  15.  
  16. #ifndef FWFILESY_H
  17. #include "FWFileSy.h"
  18. #endif
  19.  
  20. #ifndef FWEXCLIB_H
  21. #include "FWExcLib.h"
  22. #endif
  23.  
  24. #ifndef FWBNDSTR_H
  25. #include "FWBndStr.h"
  26. #endif
  27.  
  28. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  29. #include <Errors.h>
  30. #endif
  31.  
  32. #if defined(FW_BUILD_MAC) && !defined(__FINDER__)
  33. #include <Finder.h>
  34. #endif
  35.  
  36. #if defined(FW_BUILD_WIN) && !defined(__IO_H)
  37. #include <io.h>
  38. #endif
  39.  
  40.  
  41. #ifdef FW_BUILD_MAC
  42. #pragma segment FW_PFileSpecification
  43. #endif
  44.  
  45. //========================================================================================
  46. //    Template instantiations
  47. //========================================================================================
  48.  
  49. #include "FWSOMPtr.tpp"
  50.  
  51. FW_DEFINE_AUTO_TEMPLATE(FW_TSOMPtr, FW_OFileSpecification)
  52. FW_DEFINE_AUTO_TEMPLATE(FW_TSOMPtr, FW_ODirectorySpecification)
  53.  
  54. #if FW_USE_TEMPLATE_PRAGMAS
  55. #pragma template_access public
  56. #pragma template FW_TSOMPtr<FW_OFileSpecification>
  57. #pragma template FW_TSOMPtr<FW_ODirectorySpecification>
  58. #endif
  59.  
  60. #if FW_ANSI_TEMPLATE_INTANSTIATION
  61. template class FW_TSOMPtr<FW_OFileSpecification>;
  62. template class FW_TSOMPtr<FW_ODirectorySpecification>;
  63. #endif
  64.  
  65. //========================================================================================
  66. //  CLASS FW_PFileSpecification
  67. //========================================================================================
  68.  
  69. FW_DEFINE_AUTO(FW_PFileSpecification)
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //    FW_PFileSpecification::FW_PFileSpecification
  73. //
  74. //  Create a file specification from a directory and a file name.  
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_PFileSpecification::FW_PFileSpecification(Environment *ev,
  78.                                              FW_ODirectorySpecification* directory,
  79.                                              const FW_CString& fileName)
  80. {
  81.     FW_OFileSpecification *theFileSpec = new FW_OFileSpecification;
  82.  
  83.     SetRep(ev, theFileSpec);
  84.     theFileSpec->InitFromDirectoryAndName(ev, directory, fileName);
  85.  
  86.     FW_END_CONSTRUCTOR
  87. }
  88.  
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_PFileSpecification::FW_PFileSpecification
  92. //
  93. //    Initialize the specification with fileName.  If fileName is a partial pathname, then
  94. //    the current working directory is used.
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_PFileSpecification::FW_PFileSpecification(Environment *ev, const FW_CString& pathName)
  98. {
  99.     Clone(ev, pathName);
  100.  
  101.     FW_END_CONSTRUCTOR
  102. }
  103.  
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //    FW_PFileSpecification::FW_PFileSpecification
  107. //
  108. //  Acquisition constructor
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_PFileSpecification::FW_PFileSpecification(Environment *ev, FW_OFileSpecification* specification)
  112. {
  113.     SetRep(ev, specification);
  114.  
  115.     FW_END_CONSTRUCTOR
  116. }
  117.  
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_PFileSpecification::FW_PFileSpecification
  121. //
  122. //  Copy constructor
  123. //----------------------------------------------------------------------------------------
  124.  
  125. FW_PFileSpecification::FW_PFileSpecification(const FW_PFileSpecification& specificationPtr)
  126. {
  127.     FW_SOMEnvironment ev;
  128.  
  129.     Clone(ev, specificationPtr);
  130.  
  131.     FW_END_CONSTRUCTOR
  132. }
  133.  
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_PFileSpecification::~FW_PFileSpecification
  137. //----------------------------------------------------------------------------------------
  138.  
  139. FW_PFileSpecification::~FW_PFileSpecification()
  140. {
  141.     FW_START_DESTRUCTOR
  142. }
  143.  
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_PFileSpecification::operator==
  147. //
  148. //  Equality operator.  Compares the location of each file.  If the location's match, then
  149. //    the file is a match.
  150. //  Note that the Windows side is case insensitive.  On the Mac, FSSMakeFSSpec should
  151. //    normalize file names so conversion should not be necessary.
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_Boolean FW_PFileSpecification::operator==(FW_OFileSpecification* theOtherFile) const
  155. {
  156.     FW_SOMEnvironment ev;
  157.     FW_OFileSpecification *rep = GetRep();
  158.  
  159.     if (rep != 0)
  160.         return rep->IsSameAs(ev, theOtherFile);
  161.     else
  162.         return theOtherFile == 0;
  163. }
  164.  
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    FW_PFileSpecification::operator=
  168. //
  169. //  Copies info over from pre-verified file specification.  Shouldn't need to do any 
  170. //    checks.
  171. //----------------------------------------------------------------------------------------
  172.  
  173. FW_PFileSpecification& FW_PFileSpecification::operator=(const FW_PFileSpecification& theOtherFile)
  174. {
  175.     FW_SOMEnvironment ev;
  176.  
  177.     Clone(ev, theOtherFile);
  178.  
  179.     return (*this);
  180. }
  181.  
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_PFileSpecification::operator=
  185. //
  186. //    Set the name of the file.  This only changes the name, it doesn't change the previous
  187. //    path.  Reverifies the path with the new fileName.
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_PFileSpecification& FW_PFileSpecification::operator=(const FW_CString& fileName)
  191. {
  192.  
  193.     FW_SOMEnvironment ev;
  194.  
  195.     Clone(ev, fileName);
  196.  
  197.     return (*this);
  198. }
  199.  
  200.  
  201. #ifdef FW_BUILD_MAC
  202. //----------------------------------------------------------------------------------------
  203. //    FW_PFileSpecification::FW_PFileSpecification
  204. //
  205. //    Macintosh FSSpec constructor.  
  206. //----------------------------------------------------------------------------------------
  207.  
  208. FW_PFileSpecification::FW_PFileSpecification(Environment *ev, const FSSpec& macSpec)
  209. {
  210.     Clone(ev, macSpec);
  211.  
  212.     FW_END_CONSTRUCTOR
  213. }
  214. #endif
  215.  
  216.  
  217. #ifdef FW_BUILD_MAC
  218. //----------------------------------------------------------------------------------------
  219. //    FW_PFileSpecification::operator=
  220. //----------------------------------------------------------------------------------------
  221.  
  222. FW_PFileSpecification& FW_PFileSpecification::operator=(const FSSpec& macSpec)
  223. {
  224.     FW_SOMEnvironment ev;
  225.  
  226.     Clone(ev, macSpec);
  227.  
  228.     return (*this);
  229. }
  230. #endif
  231.  
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_PFileSpecification::Clone
  235. //
  236. //  Copy constructor
  237. //----------------------------------------------------------------------------------------
  238.  
  239. void FW_PFileSpecification::Clone(Environment *ev, FW_OFileSpecification* specification)
  240. {
  241.     if (GetRep() == 0)
  242.         SetRep(ev, new FW_OFileSpecification);
  243.  
  244.     GetRep()->AssignOFileSpecification(ev, specification);
  245. }
  246.  
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    FW_PFileSpecification::Clone
  250. //
  251. //  Copy constructor
  252. //----------------------------------------------------------------------------------------
  253.  
  254. void FW_PFileSpecification::Clone(Environment *ev, const FW_CString& fileName)
  255. {
  256.     if (GetRep() == 0)
  257.         SetRep(ev, new FW_OFileSpecification);
  258.  
  259.     GetRep()->InitFromFileName(ev, fileName);
  260. }
  261.  
  262.  
  263. #ifdef FW_BUILD_MAC
  264. //----------------------------------------------------------------------------------------
  265. //    FW_PFileSpecification::Clone
  266. //
  267. //  Copy constructor
  268. //----------------------------------------------------------------------------------------
  269.  
  270. void FW_PFileSpecification::Clone(Environment *ev, const FSSpec& macSpec)
  271. {
  272.     if (GetRep() == 0)
  273.         SetRep(ev, new FW_OFileSpecification);
  274.  
  275.     GetRep()->AssignFileSpec(ev, (FSSpec*) &macSpec);
  276. }
  277. #endif
  278.  
  279.  
  280.  
  281. //========================================================================================
  282. //  CLASS FW_PDirectorySpecification
  283. //========================================================================================
  284.  
  285. #ifdef FW_BUILD_MAC
  286. #pragma segment FW_PDirectorySpecification
  287. #endif
  288.  
  289. FW_DEFINE_AUTO(FW_PDirectorySpecification)
  290.  
  291. //----------------------------------------------------------------------------------------
  292. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  293. //
  294. //  Specifies the current working directory.
  295. //----------------------------------------------------------------------------------------
  296.  
  297. FW_PDirectorySpecification::FW_PDirectorySpecification()
  298. {
  299.     FW_SOMEnvironment ev;
  300.     FW_ODirectorySpecification *theFileSpec = new FW_ODirectorySpecification;
  301.  
  302.     SetRep(ev, theFileSpec);
  303.  
  304.     FW_END_CONSTRUCTOR
  305. }
  306.  
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  310. //
  311. //  Copy constructor.
  312. //----------------------------------------------------------------------------------------
  313.  
  314. FW_PDirectorySpecification::FW_PDirectorySpecification(Environment *ev, FW_ODirectorySpecification* theFileSpec)
  315. {
  316.     SetRep(ev, theFileSpec);
  317.  
  318.     FW_END_CONSTRUCTOR
  319. }
  320.  
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  324. //
  325. //  Copy constructor.
  326. //----------------------------------------------------------------------------------------
  327.  
  328. FW_PDirectorySpecification::FW_PDirectorySpecification(const FW_PDirectorySpecification& other)
  329. {
  330.     FW_SOMEnvironment ev;
  331.  
  332.     Clone(ev, other);
  333.  
  334.     FW_END_CONSTRUCTOR
  335. }
  336.  
  337.  
  338. //----------------------------------------------------------------------------------------
  339. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  340. //
  341. //  Specifies the path by string.  directoryName can be either a full or partial path
  342. //    name.  
  343. //----------------------------------------------------------------------------------------
  344.  
  345. FW_PDirectorySpecification::FW_PDirectorySpecification(Environment* ev, const FW_CString& directoryName)
  346. {
  347.     Clone(ev, directoryName);
  348.  
  349.     FW_END_CONSTRUCTOR
  350. }
  351.  
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    FW_PDirectorySpecification::~FW_PDirectorySpecification
  355. //----------------------------------------------------------------------------------------
  356.  
  357. FW_PDirectorySpecification::~FW_PDirectorySpecification()
  358. {
  359.     FW_START_DESTRUCTOR
  360. }
  361.  
  362.  
  363. //----------------------------------------------------------------------------------------
  364. //    FW_PDirectorySpecification::operator==
  365. //----------------------------------------------------------------------------------------
  366. FW_Boolean FW_PDirectorySpecification::operator==(FW_ODirectorySpecification* theOtherDir) const
  367. {
  368.     FW_SOMEnvironment ev;
  369.     FW_ODirectorySpecification *rep = GetRep();
  370.  
  371.     if (rep != 0)
  372.         return rep->IsSameAs(ev, theOtherDir);
  373.     else
  374.         return theOtherDir == 0;
  375. }
  376.  
  377.  
  378. //----------------------------------------------------------------------------------------
  379. //    FW_PDirectorySpecification::operator=
  380. //----------------------------------------------------------------------------------------
  381. FW_PDirectorySpecification& FW_PDirectorySpecification::operator=(const FW_PDirectorySpecification& theOtherDir)
  382. {
  383.     FW_SOMEnvironment ev;
  384.  
  385.     Clone(ev, theOtherDir);
  386.  
  387.     return (*this);
  388. }
  389.  
  390.  
  391. //----------------------------------------------------------------------------------------
  392. //    FW_PDirectorySpecification::operator=
  393. //
  394. //  Set the name of the directory to the value specified in directoryName.  directoryName
  395. //    should not contain any path delimiters.
  396. //----------------------------------------------------------------------------------------
  397. FW_PDirectorySpecification& FW_PDirectorySpecification::operator=(const FW_CString& directoryName)
  398. {
  399.     FW_SOMEnvironment ev;
  400.  
  401.     Clone(ev, directoryName);
  402.  
  403.     return (*this);
  404. }
  405.  
  406.  
  407. //----------------------------------------------------------------------------------------
  408. //    FW_PDirectorySpecification::operator+=
  409. //
  410. //  Adds directoryName on to the end of this directory.
  411. //  In this case, the new name is assigned to the internal FileSpec, where it is interpeted
  412. //    as a partial path.
  413. //----------------------------------------------------------------------------------------
  414. FW_PDirectorySpecification& FW_PDirectorySpecification::operator+=(const FW_CString& directoryName)
  415. {
  416.     FW_SOMEnvironment ev;
  417.  
  418.     GetRep()->AppendDirectoryName(ev, directoryName);
  419.  
  420.     return (*this);
  421. }
  422.  
  423.  
  424. #ifdef FW_BUILD_MAC
  425. //----------------------------------------------------------------------------------------
  426. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  427. //----------------------------------------------------------------------------------------
  428.  
  429. FW_PDirectorySpecification::FW_PDirectorySpecification(Environment* ev, const FSSpec& macSpec)
  430. {
  431.     Clone(ev, macSpec);
  432.  
  433.     FW_END_CONSTRUCTOR
  434. }
  435. #endif
  436.  
  437.  
  438. #ifdef FW_BUILD_MAC
  439. //----------------------------------------------------------------------------------------
  440. //    FW_PDirectorySpecification::operator=
  441. //
  442. //  Copies the Macintosh FSSpec for this directory into specification.
  443. //----------------------------------------------------------------------------------------
  444.  
  445. FW_PDirectorySpecification& FW_PDirectorySpecification::operator=(const FSSpec& macSpec)
  446. {
  447.     FW_SOMEnvironment ev;
  448.  
  449.     Clone(ev, macSpec);
  450.  
  451.     return (*this);
  452. }
  453. #endif
  454.  
  455.  
  456. //----------------------------------------------------------------------------------------
  457. //    FW_PDirectorySpecification::Clone
  458. //
  459. //  Copy constructor
  460. //----------------------------------------------------------------------------------------
  461.  
  462. void FW_PDirectorySpecification::Clone(Environment *ev, FW_ODirectorySpecification* specification)
  463. {
  464.     if (GetRep() == 0)
  465.         SetRep(ev, new FW_ODirectorySpecification);
  466.  
  467.     GetRep()->AssignOFileSpecification(ev, specification);
  468. }
  469.  
  470.  
  471. //----------------------------------------------------------------------------------------
  472. //    FW_PDirectorySpecification::Clone
  473. //
  474. //  Copy constructor
  475. //----------------------------------------------------------------------------------------
  476.  
  477. void FW_PDirectorySpecification::Clone(Environment *ev, const FW_CString& fileName)
  478. {
  479.     if (GetRep() == 0)
  480.         SetRep(ev, new FW_ODirectorySpecification);
  481.  
  482.     GetRep()->InitFromFileName(ev, fileName);
  483. }
  484.  
  485.  
  486. #ifdef FW_BUILD_MAC
  487. //----------------------------------------------------------------------------------------
  488. //    FW_PDirectorySpecification::Clone
  489. //
  490. //  Copy constructor
  491. //----------------------------------------------------------------------------------------
  492.  
  493. void FW_PDirectorySpecification::Clone(Environment *ev, const FSSpec& macSpec)
  494. {
  495.     if (GetRep() == 0)
  496.         SetRep(ev, new FW_ODirectorySpecification);
  497.  
  498.     GetRep()->AssignFileSpec(ev, (FSSpec*) &macSpec);
  499. }
  500. #endif
  501.